package org.adream.account.util;

import java.text.SimpleDateFormat;
import java.util.Random;

public class IdGenerator {
	
	/**
	 * 20位末尾的数字id
	 */
	public static int Guid = 100;

	/**
	 * 获取id
	 * @return
	 */
	public static String getGuid() {

		IdGenerator.Guid += 1;

		long now = System.currentTimeMillis();
		// 获取4位年份数字
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy");
		// 获取时间戳
		String time = dateFormat.format(now);
		String info = now + "";
		int ran = 0;
		if (IdGenerator.Guid > 999) {
			IdGenerator.Guid = 100;
		}
		ran = IdGenerator.Guid;
		return time + info + ran;
	}
	
	/**
	 * 获取4位数字
	 * @return
	 */
	public static String getRandomFour(int count) {
		StringBuffer sb = new StringBuffer();
	    String str = "0123456789";
	    Random r = new Random();
	    for(int i = 0;i < count;i++) {
	    	int num = r.nextInt(str.length());
	    	sb.append(str.charAt(num));
	    	str = str.replace((str.charAt(num) + ""), "");
	    }
	    return sb.toString();
	}
}